<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    #include("/template/common/include/_css.html")
</head>
<body>

<div class="layui-container">
    <div class="layui-row">
        <h2>登录，默认用户名密码：user1/123123</h2>
        <hr>
        <div class="layui-col-md4">

        </div>
        <div class="layui-col-md4">
            <form class="layui-form layui-form-pane" method="post" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="loginName" class="layui-input" required lay-verify="required" placeholder="账号" autocomplete="on" maxlength="16" minlength="4"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码：</label>
                    <div class="layui-input-inline">
                        <input type="password" name="pwd" class="layui-input" required lay-verify="required" placeholder="密码" maxlength="16" minlength="6"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn btn-submit" lay-submit lay-filter="sub">立即登录</button>
                    <button id="indexBtn" type="button" class="layui-btn">登录后才能获取数据</button>
                    <button id="logoutBtn" type="button" class="layui-btn">退出</button>
                </div>
            </form>
        </div>
        <div class="layui-col-md4">
            <div id="ret"></div>
        </div>
    </div>
</div>

#include("/template/common/include/_js.html")
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        // 操作对象
        var form = layui.form
            , $ = layui.jquery;

        // 提交监听
        form.on('submit(sub)', function (data) {
            util.sendAjax ({
                type: 'POST',
                url: '#(ctxPath)/postLogin',
                data: $.param(data.field),
                loadFlag: true,
                success : function(data) {

                }
            });

            return false;
        });

        $("#indexBtn").click(function(){
            util.sendAjax ({
                type: 'GET',
                url: '#(ctxPath)/',
                loadFlag: true,
                notice: false,
                success : function(data) {
                    layer.alert(JSON.stringify(data), {icon: 1});
                }
            });
        });

        $("#logoutBtn").click(function(){
            util.sendAjax ({
                type: 'POST',
                url: '#(ctxPath)/logout',
                loadFlag: true,
                notice: true,
                success : function(data) {

                }
            });
        });
    })

</script>
</body>
</html>